package com.example.nacosdemo.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.nacosdemo.entity.User;
import com.example.nacosdemo.mapper.UserMapper;
import com.example.nacosdemo.service.UserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    private final UserMapper userMapper;


    @Override
    public void add(User user) {
        this.saveOrUpdate(user);
    }

    @Override
    public User findById(User user) {
        return this.getById(user.getId());
    }

    @Override
    public void kafkaAdd(String message) {
        User user = JSON.parseObject(message, User.class);
        this.saveOrUpdate(user);
        log.info("创建成功");
    }


}
